
import React from 'react';
import { Form, Switch } from "antd";
import * as THREE from 'three';
import Controller from 'Controller';

/** 产生阴影 */
export default function CastShadow(props: { object3D: THREE.Object3D<THREE.Event> }) {

    const { object3D } = props;

    const threeController = Controller.instance.useMemo(s => s.threeController, [])

    const onChangeCastShadow = React.useCallback((e: boolean) => {
        if (!object3D) return;
        object3D.castShadow = e;
        object3D.traverse(child => {
            child.castShadow = e;
        })
        threeController.run(async s => { s.elementMap = new Map(s.elementMap) })
    }, [object3D, threeController])

    return (
        <Form.Item label='产生阴影' tooltip='castShadow - 对象是否被渲染到阴影贴图中。' >
            <Switch
                size='small'
                checked={object3D.castShadow}
                onChange={onChangeCastShadow}
            />
        </Form.Item>
    )
}